import java.util.*;

class CalendarSeeker {

    static final String[][] DAYS_IN_MONTH = {
        {"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"},
        {"31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"}
    };
    static final String[] DAY_OF_WEEK = {"Monday", "Thuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String[] input = new String[0];
        int refernceDay = 719538;

        do {
            System.out.print("Enter date (example: dd <Month> yyyy): ");
            input = in.nextLine().split(" ");
        }
        while (!verifyInput(input));

        int passedDays = numberOfPassedDays(input);

        //Determine day of week
        int diff = Math.abs(passedDays - refernceDay - 2);
        diff = diff % 7;
        System.out.println("Day: " + DAY_OF_WEEK[diff]);

    }

    public static int numberOfPassedDays(String[] input) {
        //Count days based on passed years
        int result = Integer.parseInt(input[2]) * 365 + Integer.parseInt(input[2])/4;

        //Search current month indx
        String month = input[1].toLowerCase();
        int monthNumb = 0;
        for (int i = 0; i < 12; i++) {
            if (month.equals(DAYS_IN_MONTH[0][i])) {
                monthNumb = i;
                break;
            }
        }

        //Add month's passed days
        for (int i = 0; i < monthNumb; i++) result += Integer.parseInt(DAYS_IN_MONTH[1][i]);

        //Add date
        result += Integer.parseInt(input[0]);

        return result;
    }

    public static boolean verifyInput(String[] str) {
        //Verify input using regexp
        if (Arrays.toString(str).matches("\\[\\d{1,2},\\s[a-zA-Z]{2,9},\\s\\d+\\s*\\]")) {
            return true;
        } else {
            System.out.println("Please, revise input. Pattern mismatch.");
            return false;
        }
    }


}